using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Betarium.PotonEditor
{
	public partial class SizeForm : Form
	{
		protected Size m_BeforeSize;
		protected Size m_CurrentSize;
		protected bool m_bSkipUpdate;
		public SizeForm()
		{
			InitializeComponent();
		}

		private void m_ctrlWidth_TextChanged(object sender, EventArgs e)
		{
			if (m_BeforeSize.Width == 0 || m_BeforeSize.Height == 0)
				return;
			if (!m_ctrlFixedRate.Checked)
				return;
			if (m_bSkipUpdate)
			{
				m_bSkipUpdate = false;
				return;
			}

			string sValue = m_ctrlWidth.Text;
            int dummy = 0;
            if (sValue.Length == 0 || !Int32.TryParse(sValue, out dummy))
				return;
			int nValue = Int32.Parse(sValue);
			m_CurrentSize.Width = nValue;
			int nNewSize = (int)((double)nValue * m_BeforeSize.Height / m_BeforeSize.Width);
			if (m_ctrlHeight.Text == nNewSize.ToString())
				return;
			if (m_CurrentSize.Height == nNewSize)
				return;
			m_bSkipUpdate = true;
			m_CurrentSize.Height = nNewSize;
			m_ctrlHeight.Text = nNewSize.ToString();
		}

		private void m_ctrlHeight_TextChanged(object sender, EventArgs e)
		{
			if (m_BeforeSize.Width == 0 || m_BeforeSize.Height == 0)
				return;
			if (!m_ctrlFixedRate.Checked)
				return;
			if (m_bSkipUpdate)
			{
				m_bSkipUpdate = false;
				return;
			}
			string sValue = m_ctrlHeight.Text;
            int dummy = 0;
            if (sValue.Length == 0 || !Int32.TryParse(sValue, out dummy))
                return;
			int nValue = Int32.Parse(sValue);
			m_CurrentSize.Height = nValue;

			int nNewSize = (int)((double)nValue * m_BeforeSize.Width / m_BeforeSize.Height);
			if (m_ctrlWidth.Text == nNewSize.ToString())
				return;
			if (m_CurrentSize.Width == nNewSize)
				return;
			m_bSkipUpdate = true;
			m_ctrlWidth.Text = nNewSize.ToString();
		}

		private void SizeForm_Load(object sender, EventArgs e)
		{
			m_BeforeSize = new Size(Int32.Parse(m_ctrlWidth.Text), Int32.Parse(m_ctrlHeight.Text));
		}

        private void m_ctrlOk_Click(object sender, EventArgs e)
        {

        }
	}
}